/*
 * @Author: zhang ke
 * @Date: 2025-06-28 15:23:31
 * @LastEditors: your name
 * @LastEditTime: 2025-07-05 16:35:35
 * @Description: SPU接口
 * @FilePath: \vue3-admin\src\api\product\spu\index.ts
 */
import request  from "@/utils/request";
import type {HasSpuResponseData,AllTradeMark,SpuHasImg,SaleAttrResponseData,SpuData,SkuData,
SkuInfoData
} from '@/api/product/spu/type'
// 接口地址
enum API{
    HASSPU_URL = '/admin/product/',
    ALLTRADEMARK_URL = '/admin/product/baseTrademark/getTrademarkList',
    IMAGE_URL = '/admin/product/spuImageList/',
    SPUHASSALEATTR_URL = '/admin/product/spuSaleAttrList/',
    ALLSALEATTR_URL = '/admin/product/baseSaleAttrList',
    ADDSPU_URL = '/admin/product/saveSpuInfo',
    UPDATESPU_URL = '/admin/product/updateSpuInfo',
    ADDSKU_URL = '/admin/product/saveSkuInfo',
    SKUINFO_URL = '/admin/product/findBySpuId/',
    REMOVESPU_URL = '/admin/product/deleteSpu/',
}

//spu table列表接口
export const reqHasSpu = (page:number,limit:number,category3Id:string|number)=>{
    return request.get<any,HasSpuResponseData>(API.HASSPU_URL+`${page}/${limit}/${category3Id}`)
}

export const reqAllTradeMark = () =>
  request.get<any, AllTradeMark>(API.ALLTRADEMARK_URL)

export const reqSpuImageList = (spuId: number) =>
  request.get<any, SpuHasImg>(API.IMAGE_URL + spuId)

export const reqSpuHasSaleAttr = (spuId: number) =>
  request.get<any, SaleAttrResponseData>(API.SPUHASSALEATTR_URL + spuId)

export const reqAllSalAttr = () => request.get<any, any>(API.ALLSALEATTR_URL)

export const reqAddOrUpdateSpu = (data: SpuData) => {
  if (data.id) {
    return request.post<any, any>(API.UPDATESPU_URL, data)
  } else {
    return request.post<any, any>(API.ADDSPU_URL, data)
  }
}

//添加sku 
export const reqAddSku = (data:SkuData)=>{
  return request.post<any,any>(API.ADDSKU_URL+ data)
}

//获取sku列表
export const reqSkuList = (spuId:number| string)=>{
  return request.get<any,SkuInfoData>(API.SKUINFO_URL + spuId )
}
//删除spu

export const reqRemoveSpu = (spuId:number| string)=>{
  return request.delete<any,any>(API.REMOVESPU_URL + spuId)
}